﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <!--[if lt IE 9]>
<script type="text/javascript" src="../lib/html5.js"></script>
<script type="text/javascript" src="../lib/respond.min.js"></script>
<script type="text/javascript" src="../lib/PIE_IE678.js"></script>
<![endif]-->
    <link href="../lib/layui/css/layui.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.min.css" rel="stylesheet" type="text/css" />
    <link href="../css/H-ui.admin.css" rel="stylesheet" type="text/css" />
    <link href="../lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
    <link href="../lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
<script type="text/javascript" src="../lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
    <title>入库管理</title>

</head>
<body>
    <div class="pt-5  pl-20 pr-20 pb-20">
        <form id="itemEdit" name="itemEdit" method="post" action="../ashx/spui.ashx" class="form form-horizontal">
            <input type="hidden" class="actionValue" id="editAction" name="action" value="add" />
            <input type="hidden" id="id" name="id" />
            <input type="hidden" id="fgid" name="fgid" value="" />
            <input type="hidden" id="tablename" name="tablename" value="" />
            <input type="hidden" id="tablemidname" name="tablemidname" value="" />
            <!-- <input type="hidden" id="fstate" name="fstate" value="草稿" />-->
            <input type="hidden" id="dataneedtouser" name="dataneedtouser" value="1" /><!--是否要包含通用数据必归属处理-->


            <ul>
                <li class="item">
                    <h4>单据信息<b></b></h4>

                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="row cl">
                                <label class="form-label col-1">仓库：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="fstoreid" id="fstoreid" nullmsg="请选择"></select>
                                    </span>
                                </div>
                            </div>
                            <div class="row cl">
                                <label class="form-label col-1">入库类型：</label>
                                <div class="formControls col-3">
                                    <input type="hidden" id="ftype" name="ftype" value="入库" />
                                    <span class="select-box">
                                        <select class="select" size="1" name="fsontype" id="fsontype" nullmsg="请选择">
                                        </select></span>
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">入库日期：</label>
                                <div class="formControls col-3">
                                    <input type="text"  name="forderNo" id="forderNo" placeholder="入库日期" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})"  class="input-text Wdate" />
                                </div>
                                <div class="col-1"></div>
                            </div>
                            <div class="row cl">
                                <label class="form-label col-1">说明：</label>
                                <div class="formControls col-3">
                                    <input type="text" class="input-text" name="fsontypeinfo" id="fsontypeinfo" placeholder="单据说明、生产订单说明" />
                                </div>
                                <div class="col-1"></div>
                                <label class="form-label col-1">处理方式：</label>
                                <div class="formControls col-2">
                                    <span class="select-box">
                                        <select class="select" size="1" name="fstate" id="fstate">
                                            <option value="提交入库">同步库存</option>
                                            <option value="待入库">暂存-不同步库存</option>
                                            <option value="完成">完成-不会再同步库存</option>
                                        </select>
                                    </span>
                                </div>
                            </div>
                            <div class="row cl">
                                <label class="form-label col-1">交接人：</label>
                                <div class="formControls col-3">
                                    <input type="text" class="input-text" name="finoutusername" id="finoutusername" readonly="readonly" placeholder="右边选择或搜索选择" />
                                    <input type="hidden" id="finoutuserid" name="finoutuserid" />
                                </div>
                                <div class="col-3 layui-form">
                                    <select name="inoutusernamesel" id='inoutusernamesel' lay-filter="testselect" lay-verify="required" lay-search="">
                                        <option value="">直接选择或搜索选择</option>
                                    </select>
                                </div>

                            </div>
                        </div>
                    </div>

                </li>
                <li class="item">
                    <h4>物品信息<b></b></h4>

                    <div class="panel panel-primary">
                        <div class="panel-body">
                            <div class="row cl">
                                <div class="formControls col-2">
                                    分类:
                                        <span class="select-box">
                                            <select class="select" size="1" name="selfproducttype" id="selfproducttype" placeholder="分类"></select></span>
                                    <input type="hidden" class="input-text" name="selunit" id="selunit" value="单位" placeholder="2~10个字符" />
                                </div>
                                <div class="col-2 layui-form">
                                    物品：
                                        <select name="selherp_product" id='selherp_product' lay-filter="selherp_product" lay-search="">
                                            <option value="">直接选择或搜索选择</option>
                                        </select>
                                </div>
                                <div class="formControls col-2">
                                    入库量(<label id="lable_dw"></label>)：
                                        <input type="text" class="input-text" placeholder="数量" name="selcount" id="selcount" value="1" />
                                </div>
                                <div class="formControls col-2">
                                    单价：
                                        <input type="text" class="input-text" name="selprice" placeholder="单价" id="selprice" value="1" />
                                </div>
                                <div class="formControls col-2">
                                    厂家：
                                        <input type="text" class="input-text" name="selspbasecj" placeholder="厂家" id="selspbasecj" />
                                </div>
                                <div class="formControls col-2">
                                    资质：
                                        <input type="text" class="input-text" name="selspbasezj" placeholder="资质" id="selspbasezj" />
                                </div>
                            </div>
                            <div class="row cl">
                                <div class="formControls col-2">
                                    生产批号：
                                        <input type="text" class="input-text" name="selspbasepc" placeholder="生产批号" id="selspbasepc" />
                                </div>
                                <div class="formControls col-2">
                                    生产日期：
                                        <input type="text" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" name="selspbasecdate" id="selspbasecdate" class="input-text Wdate" />
                                </div>
                                <div class="formControls col-2">
                                    说明：
                                        <input type="text" class="input-text" name="selspbasedesc" placeholder="说明" id="selspbasedesc" />
                                </div>
                                <div class="formControls col-2">
                                    <br />
                                    <button onclick="addOrderSpListInfo();" class="btn btn-danger radius" type="button">添加</button>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="panel panel-success">
                        <div class="panel-header">入库列表</div>
                        <div id="tableArea">
                            <table class="table table-border table-bordered table-striped table-hover" id="tablelist" style="width: 100%;">
                                <thead>
                                    <tr class="text-c">
                                        <th width="30"><a id="hcmtable_sall" onclick="hcmtable_sall();" href="javascript:;" title="全选反选"><i class="Hui-iconfont">&#xe608;全</i></a></th>
                                        <th>主分类</th>
                                        <th>名称</th>
                                        <th>金额</th>
                                        <th>数量</th>
                                        <th>单位</th>
                                        <th>厂家</th>
                                        <th>资质</th>
                                        <th>批次</th>
                                        <th>生产日期</th>
                                        <th>说明</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </li>
            </ul>

            <div class="row cl">
                <div class="col-6 col-offset-4">
                    <!-- <button onclick="changeshowtype();" class="btn btn-danger radius" type="button">切换显示</button>&nbsp;&nbsp;&nbsp;&nbsp;-->
                    <button class="btn btn-primary radius" type="submit" id="btsub1">保存</button>&nbsp;&nbsp;
				<button class="btn btn-secondary radius" type="button" id="btn_reset">重置</button>&nbsp;&nbsp;
                    <button onclick="layer_close();" class="btn btn-default radius" type="button">返回</button>
                </div>
            </div>

        </form>
    </div>
    <script src="../hcjsui/Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
    <script type="text/javascript" src="../lib/layui/layui.js"></script>
    <script type="text/javascript" src="../lib/icheck/jquery.icheck.min.js"></script>
    <script type="text/javascript" src="../lib/Validform/5.3.2/Validform.js"></script>
    <script type="text/javascript" src="../lib/layer/1.9.3/layer.js"></script>
    <script src="../hcjsui/js/_Define.js" type="text/javascript"></script>
    <script type="text/javascript" src="../js/hcui.js"></script>
    <script type="text/javascript" src="../js/hcui_au.js"></script>
    <script type="text/javascript" src="../js/hcrainwf.js"></script>
    <script type="text/javascript" src="../lib/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="../lib/datatables/1.10.0/jtable.js"></script>
    <script type="text/javascript" src="../js/hcui_list.js"></script>

    <script type="text/javascript">
        var uiform = null;
        var divshowtype = 2;
        HcUiAuloadInfoAuto = false;//将自动加载，设置为false（禁用自动加载）
        var loadisOk = 3;
        //初始化
        //$('#fsontype').append('<option value="发货出库">发货出库-出库</option>');
        //$('#fsontype').append('<option value="生产取料">生产取料-出库</option>');
        //$('#fsontype').append('<option value="销售出库">销售出库-出库</option>');
        //$('#fsontype').append('<option value="其它出库">其它出库-出库</option>');

        $('#fsontype').append('<option value="生产采购">生产采购-入库</option>');
        $('#fsontype').append('<option value="生产完成入库">生产完成-入库</option>');
        $('#fsontype').append('<option value="日常采购">日常采购-入库</option>');
        $('#fsontype').append('<option value="其它入库">其它入库-入库</option>');


        //当前关联对象信息--人员
        var inoutusernameselObj = [];
        //当前关联对象信息--物品
        var inoutproductObj = [];
        //动态加载--物品明细
        $('#selfproducttype').change(function () {
            var type = $(this).children('option:selected').val();
            if (type == "") {
                hcdosel("id,concat(productno) as name,unit", "herp_product", "producttype='清空'  and databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#selherp_product", data);
                    inoutproductObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
            else {
                hcdosel("id,concat(productno) as name,unit", "herp_product", "producttype='" + type + "' and databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                    SetSelectWithObjIdName("#selherp_product", data);
                    inoutproductObj = JSON.parse(data);
                    uiform.render('select');
                });
            }
        });
        //加载处理
        function loadin() {
            layui.use(['form'], function () {
                uiform = layui.form();
                uiform.on('select(testselect)', function (data) {//选择交接人处理
                    $('#finoutuserid').val(data.value);
                    $('#finoutusername').val($("#inoutusernamesel").find("option:selected").text());
                    //加载明细
                    //var objget = hcgetJsonObjById(inoutusernameselObj, data.value);
                    //$('#finoutuserteluser').val(objget.username);
                    //$('#finoutusertel').val(objget.tel);
                    //$('#finoutuseraddress').val(objget.address);
                });
                uiform.on('select(selherp_product)', function (data) {//物品选择处理
                    var unit = hcgetJsonObjById(inoutproductObj, data.value).unit;
                    $('#selunit').val(unit);
                   
                    $('#lable_dw').text(unit);
                });

            });
            if (getUrlParam("action") == "add") {
                $("#fgid").val(NewGuid());
                table_reset();
            }
            //本页面 
            spsetBase("herp_inoutorder", "id", "herp_inoutorder as T", "*", "#tablelist", "herp_inoutorder", "出入库管理", "StoreInOut");
            hcui_ajaxasync = true;
            //下拉加载-仓库
            hcdoselbyPost("id,name", "herp_storehouse", "databranchid='" + HCUser.HCUorg + "'", "", "", "id", function (data) {
                SetSelectWithArrayIdName("#fstoreid", data);
                $('#fstoreid option:eq(1)').attr('selected', 'selected');//选择第二(1)个
                loadisOk--;
                if (loadisOk <= 0 && auhcotype == "edit") {
                    hcui_ajaxasync = true;//恢复异步
                    loadInfoById(aumid, function (data) {
                        loadback(data);
                    });
                }
            });

            //下拉加载 --物品主分类
            hcdoselbyPost("dictdata_code as id,dictdata_name as name", "dictionarydata", "dict_code='ErpProductMtype'", "", "", "orderindex",
                   function (data) {
                       SetSelectWithArrayIdName("#selfproducttype", data);
                       loadisOk--;
                       if (loadisOk <= 0 && auhcotype == "edit") {
                           hcui_ajaxasync = true;//恢复异步
                           loadInfoById(aumid, function (data) {
                               loadback(data);
                           });
                       }
                   });
            //下拉加载 --人员
            hcdoselbyPost("empid  as id,concat(depname,'-',empname) as name,empname as username,mobile as  tel,depname as address", "view_user", "branchid='" + HCUser.HCUorg + "'", "", "", "id",
                function (data) {
                    SetSelectWithArrayIdName("#inoutusernamesel", data);
                    loadisOk--;
                    if (loadisOk <= 0 && auhcotype == "edit") {
                        hcui_ajaxasync = true;//恢复异步
                        loadInfoById(aumid, function (data) {
                            loadback(data);
                        });
                    }
                    uiform.render('select');
                });


            //$.Huitab("#tab-category .tabBar span", "#tab-category .tabCon", "current", "click", "0");
            // $.Huifold("#Huifold2 .item h4", "", "2", 1, "click"); /*5个参数顺序不可打乱，分别是：相应区,隐藏显示的内容,速度,类型,事件 mouseover click */
            ////三种类型：分别对应的参数：1	只打开一个，可以全部关闭2	必须有一个打开3	可打开多个
            //changeshowtype();
        }
        function table_reset() {
            hcmtable = $("#tablelist").DataTable({
                "serverSide": true,//服务端处理分页 无法使用当前查找
                "bFilter": false,  //是否使用内置的过滤功能
                "bLengthChange": false, //改变每页显示数据数量
                "ajax": {
                    "type": "POST",
                    "url": sposelUrl("herp_inoutorderlist", "id,spbasecj,spbasezj,spbasepc,spbasecdate,spbasedesc,gid,ordergid,spid,spname,count,price,state,unit,'desc',storeid,spmaintype,spsubtype,(count * price) as allmoney", " and ordergid='" + $("#fgid").val() + "'") + "&sporderby=id",
                    "data": function (d) {
                    }
                },
                aLengthMenu: [100],
                "columns": [
                     { "data": "rowhcindex" }
        , { "data": "spmaintype" }
        , { "data": "spname" }
        , { "data": "price" }
        , { "data": "count" }
        , { "data": "unit" }, { "data": "spbasecj" }, { "data": "spbasezj" },
        { "data": "spbasepc" }, { "data": "spbasecdate" }, { "data": "spbasedesc" }
        , { "data": "id" }

                ],
                "columnDefs": [

                    {
                        "targets": [11],
                        "render": function (data, type, row) {
                            if (loadbackdata.state == '完成')
                            { return "<a style=\"text-decoration:none\" class=\"ml-5\" onClick=\"toolUpdateById(" + data + ", '编辑入库信息', 'StoreInOutList-ae.html?action=edit&id=' + " + data + ")\" href=\"javascript:;\" title=\"编辑\"><i class=\"Hui-iconfont\">&#xe6df;编辑</i></a> "; }
                            else
                                return "<a style=\"text-decoration:none\" class=\"ml-5\" onclick=\"toolDelete('" + data + "','herp_inoutorderlist','id')\"     href=\"javascript:;\" title=\"删除\"><i class=\"Hui-iconfont\">&#xe6e2;删除</i></a>";
                        }
                    },

                {
                    "orderable": false,
                    "targets": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                }
                ]
            });
        }
        //function loadback(data) {
        //    console.log(data);
        //    $('#ftype').change();//主分类
        //    $("#fsontype").val(data["sontype"]);//重新 设置子分类
        //    $("#finoutusertype").val(data["inoutusertype"]);//重新 对象分类
        //    $('#finoutusertype').change();
        //}
        //切换事件
        function changeshowtype() {
            if (divshowtype == 1) {
                $("#divshow1").appendTo("#divfold1");
                $("#divshow2").appendTo("#divfold2");
                $("#divshow3").appendTo("#divfold3");
                $("#fold_category").show();
                $("#tab-category").hide();

                divshowtype = 2;
            }
            else {
                $("#divshow1").appendTo("#divtab1");
                $("#divshow2").appendTo("#divtab2");
                $("#divshow3").appendTo("#divtab3");
                $("#fold_category").hide();
                $("#tab-category").show();
                divshowtype = 1;
            }

        }

        var oldstate = "待入库";
        var loadbackdata = [];
        //加载完成后,加载明细列表
        function loadback(data) {
            table_reset();
            loadbackdata = data;
            oldstate = loadbackdata.state;
            if (loadbackdata.state == '完成')//已完成，不能修必出入库状态
            {
                $("#fstate").attr("disabled", "disabled");
                // $("#btsub1").hide();
            }
            if (getUrlParam("action") == "edit") {
                $("#fstoreid").attr("disabled", "disabled");
            }

        }
        //添加商品明细
        function addOrderSpListInfo() {
            if ($("#fstoreid").val() == "") {
                layer.msg('仓库不能为空', { icon: 1 });
                return;
            }
            if (loadbackdata.state == '完成') {
                layer.msg('当前状态不能操作', { icon: 1 });
                return;
            }
            if ($("#selherp_product").val() == "") {
                layer.msg('请选择物品信息', { icon: 2 });
                return;
            }
            if ($("#selspbasepc").val() == "") {
                layer.msg('批次不能为空', { icon: 2 });
                return;
            }
            if ($("#selspbasecj").val() == "") {
                layer.msg('厂家不能为空', { icon: 2 });
                return;
            } if ($("#selprice").val() == "") {
                layer.msg('单价不能为空', { icon: 2 });
                return;
            } if ($("#selspbasecdate").val() == "") {
                layer.msg('生产日期不能为空', { icon: 2 });
                return;
            }
            if (!hcisbnum($("#selprice").val())) {
                layer.msg('单价的数值无效', { icon: 2 });
                return;
            }

            if (!hcisbnum($("#selcount").val())) {
                layer.msg('入库量的数值无效', { icon: 2 });
                return;
            }
            $("#fstoreid").attr("disabled", "disabled");
            var addinfo = "gid%" + NewGuid()
                + "$ordergid%" + $("#fgid").val()
                + "$spmaintype%" + $("#selfproducttype").find("option:selected").text()
                + "$spid%" + $("#selherp_product").val()
                + "$spname%" + $("#selherp_product").find("option:selected").text()
                + "$count%" + $("#selcount").val()
                + "$spbasecj%" + $("#selspbasecj").val()
                + "$spbasezj%" + $("#selspbasezj").val()
                + "$spbasepc%" + $("#selspbasepc").val()
                + "$spbasecdate%" + $("#selspbasecdate").val()
                + "$spbasedesc%" + $("#selspbasedesc").val() + "$hasout%0"
                + "$price%" + $("#selprice").val()
                + "$storeid%" + $("#fstoreid").val()
                + "$unit%" + $("#selunit").val();
            hcdoadd2017("herp_inoutorderlist", addinfo, 1, "", function (info) {
                console.log(info);
                if (info == "ok") hcmtable.ajax.reload();
                else {
                    layer.msg(info, { icon: 2 });
                }


            });
        }
        //提交数据后,回调
        function subback(data) {
            if (data.status == "y") {
                var showmessage = "处理成功";
                if (loadbackdata.state != '完成') {
                    if ($("#fstate").val() == "提交入库") {               //分析是否要同步库存
                        //提交同步数据
                        $.ajax({
                            type: "get",
                            url: spPageUrl,
                            data: {
                                "action": "doProc",
                                "procName": "doProcInorderOK",
                                "hcporderguid": $("#fgid").val()
                            },
                            timeout: 30,
                            async: false,
                            cache: false,
                            error: function () {
                                alert("error");
                            },
                            success: function (re) {
                                var data = JSON.parse(re);
                                if (data.message == JsonResult.Success) {
                                    showmessage = data.data;
                                    hcapigetNoError("../api/Task/GetStoreTask", {}, function (backdata) {
                                    });
                                }
                                else {
                                    layer.alert(data.data, { icon: 2 });
                                    return;
                                }
                            }
                        });

                    }
                }
                if (getUrlParam("action") == "add") {
                    if ($("#fgid")) { $("#fgid").val(NewGuid()); }
                }

                layer.confirm(showmessage, {
                    btn: ['确认'] //按钮
                }, function (index) {
                    layer_close();
                    //layer.msg('继续添加', { icon: 1 });
                    //$("#btn_reset").click();
                    //table_reset();
                }, function (index) {
                    layer_close();
                });


                //layer.alert(data.info, { icon: 1 });

            }
            else {
                layer.alert(data.info, { icon: 2 });
            }
        }
        //重写  提交前数据处理
        function hcrBeforeSub() {
            $("#fstoreid").removeAttr("disabled");
        }

    </script>
</body>
</html>
